import {ElMessage} from "element-plus";
import * as XLSX from "xlsx";
import { saveAs } from 'file-saver'

export default function handleExport(exportData,filename) {
    if (exportData.length === 0) {
        ElMessage.warning('没有可导出的数据');
        return;
    }

    console.log(exportData)

    const worksheet = XLSX.utils.json_to_sheet(exportData);
    const workbook = XLSX.utils.book_new();
    XLSX.utils.book_append_sheet(workbook, worksheet, filename);

    const wbout = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
    const blob = new Blob([wbout], { type: 'application/octet-stream' });

    saveAs(blob, filename+'.xlsx');
    ElMessage.success('导出成功');
}